package com.develop.archives.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.develop.archives.domain.ElevatorDO;
import com.develop.archives.service.ElevatorService;
import com.develop.common.utils.PageUtils;
import com.develop.common.utils.Query;
import com.develop.common.utils.R;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2019-04-08 14:57:48
 */
 
@Controller
@RequestMapping("archives/elevator")
public class ElevatorController {
	@Autowired
	private ElevatorService elevatorService;
	
	@GetMapping()
	@RequiresPermissions("archives:elevator:elevator")
	String Elevator(){
	    return "archives/elevator/elevator";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("archives:elevator:elevator")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ElevatorDO> elevatorList = elevatorService.list(query);
		int total = elevatorService.count(query);
		PageUtils pageUtils = new PageUtils(elevatorList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("archives:elevator:add")
	String add(){
	    return "archives/elevator/add";
	}

	@GetMapping("/edit/{elevatorid}")
	@RequiresPermissions("archives:elevator:edit")
	String edit(@PathVariable("elevatorid") String elevatorid,Model model){
		ElevatorDO elevator = elevatorService.get(elevatorid);
		model.addAttribute("elevator", elevator);
	    return "archives/elevator/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("archives:elevator:add")
	public R save( ElevatorDO elevator){
		if(elevatorService.save(elevator)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("archives:elevator:edit")
	public R update( ElevatorDO elevator){
		elevatorService.update(elevator);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("archives:elevator:remove")
	public R remove( String elevatorid){
		if(elevatorService.remove(elevatorid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("archives:elevator:batchRemove")
	public R remove(@RequestParam("ids[]") String[] elevatorids){
		elevatorService.batchRemove(elevatorids);
		return R.ok();
	}
	
}
